<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>



<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/"><title>reStructuredText Interpreted Text Roles</title>

<meta name="author" content="David Goodger">
<meta name="date" content="2006-05-21">
<meta name="copyright" content="This document has been placed in the public domain.">
<link rel="stylesheet" href="roles_files/html4css1.css" type="text/css"></head><body>
<div class="document" id="restructuredtext-interpreted-text-roles">
<h1 class="title">reStructuredText Interpreted Text Roles</h1>
<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name">
<col class="docinfo-content">
<tbody valign="top">
<tr><th class="docinfo-name">Author:</th>
<td>David Goodger</td></tr>
<tr><th class="docinfo-name">Contact:</th>
<td><a class="first last reference" href="mailto:goodger@python.org">goodger@python.org</a></td></tr>
<tr><th class="docinfo-name">Revision:</th>
<td>4564</td></tr>
<tr><th class="docinfo-name">Date:</th>
<td>2006-05-21</td></tr>
<tr><th class="docinfo-name">Copyright:</th>
<td>This document has been placed in the public domain.</td></tr>
</tbody>
</table>
<p>This document describes the interpreted text roles implemented in the
reference reStructuredText parser.</p>
<p>Interpreted text uses backquotes (`) around the text.  An explicit
role marker may optionally appear before or after the text, delimited
with colons.  For example:</p>
<pre class="literal-block">This is `interpreted text` using the default role.

This is :title:`interpreted text` using an explicit role.
</pre>
<p>A default role may be defined by applications of reStructuredText; it
is used if no explicit <tt class="docutils literal"><span class="pre">:role:</span></tt> prefix or suffix is given.  The
"default default role" is <a class="reference" href="#title-reference">:title-reference:</a>.  It can be changed
using the <a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/directives.html#default-role">default-role</a> directive.</p>
<p>See the <a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#interpreted-text">Interpreted Text</a> section in the <a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html">reStructuredText Markup
Specification</a> for syntax details.  For details on the hierarchy of
elements, please see <a class="reference" href="http://docutils.sourceforge.net/docs/ref/doctree.html">The Docutils Document Tree</a> and the <a class="reference" href="http://docutils.sourceforge.net/docs/ref/docutils.dtd">Docutils
Generic DTD</a> XML document type definition.  For interpreted text role
implementation details, see <a class="reference" href="http://docutils.sourceforge.net/docs/howto/rst-roles.html">Creating reStructuredText Interpreted
Text Roles</a>.</p>
<div class="contents topic">
<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
<ul class="simple">
<li><a class="reference" href="#customization" id="id5" name="id5">Customization</a></li>
<li><a class="reference" href="#standard-roles" id="id6" name="id6">Standard Roles</a><ul>
<li><a class="reference" href="#emphasis" id="id7" name="id7"><tt class="docutils literal"><span class="pre">:emphasis:</span></tt></a></li>
<li><a class="reference" href="#literal" id="id8" name="id8"><tt class="docutils literal"><span class="pre">:literal:</span></tt></a></li>
<li><a class="reference" href="#pep-reference" id="id9" name="id9"><tt class="docutils literal"><span class="pre">:pep-reference:</span></tt></a></li>
<li><a class="reference" href="#rfc-reference" id="id10" name="id10"><tt class="docutils literal"><span class="pre">:rfc-reference:</span></tt></a></li>
<li><a class="reference" href="#strong" id="id11" name="id11"><tt class="docutils literal"><span class="pre">:strong:</span></tt></a></li>
<li><a class="reference" href="#subscript" id="id12" name="id12"><tt class="docutils literal"><span class="pre">:subscript:</span></tt></a></li>
<li><a class="reference" href="#superscript" id="id13" name="id13"><tt class="docutils literal"><span class="pre">:superscript:</span></tt></a></li>
<li><a class="reference" href="#title-reference" id="id14" name="id14"><tt class="docutils literal"><span class="pre">:title-reference:</span></tt></a></li>
</ul>
</li>
<li><a class="reference" href="#specialized-roles" id="id15" name="id15">Specialized Roles</a><ul>
<li><a class="reference" href="#raw" id="id16" name="id16"><tt class="docutils literal"><span class="pre">raw</span></tt></a></li>
</ul>
</li>
</ul>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id5" id="customization" name="customization">Customization</a></h1>
<p>Custom interpreted text roles may be defined in a document with the
<a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/directives.html#role">"role" directive</a>.  Customization details are listed with each role.</p>
<p id="class">A <tt class="docutils literal"><span class="pre">class</span></tt> option is recognized by the "role" directive for most
interpreted text roles.  A <a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/directives.html#role-class">description</a> is provided in the <a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/directives.html#role">"role"
directive</a> documentation.</p>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id6" id="standard-roles" name="standard-roles">Standard Roles</a></h1>
<div class="section">
<h2><a class="toc-backref" href="#id7" id="emphasis" name="emphasis"><tt class="docutils literal"><span class="pre">:emphasis:</span></tt></a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Aliases:</th><td class="field-body"><p class="first">None</p>
</td>
</tr>
<tr class="field"><th class="field-name">DTD Element:</th><td class="field-body"><p class="first">emphasis</p>
</td>
</tr>
<tr class="field"><th class="field-name">Customization:</th><td class="field-body"><table class="first last docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Options:</th><td class="field-body"><a class="reference" href="#class">class</a>.</td>
</tr>
<tr class="field"><th class="field-name">Content:</th><td class="field-body">None.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>Implements emphasis.  These are equivalent:</p>
<pre class="literal-block">*text*
:emphasis:`text`
</pre>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id8" id="literal" name="literal"><tt class="docutils literal"><span class="pre">:literal:</span></tt></a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Aliases:</th><td class="field-body"><p class="first">None</p>
</td>
</tr>
<tr class="field"><th class="field-name">DTD Element:</th><td class="field-body"><p class="first">literal</p>
</td>
</tr>
<tr class="field"><th class="field-name">Customization:</th><td class="field-body"><table class="first last docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Options:</th><td class="field-body"><a class="reference" href="#class">class</a>.</td>
</tr>
<tr class="field"><th class="field-name">Content:</th><td class="field-body">None.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>Implements inline literal text.  These are equivalent:</p>
<pre class="literal-block">``text``
:literal:`text`
</pre>
<p>Care must be taken with backslash-escapes though.  These are <em>not</em>
equivalent:</p>
<pre class="literal-block">``text \ and \ backslashes``
:literal:`text \ and \ backslashes`
</pre>
<p>The backslashes in the first line are preserved (and do nothing),
whereas the backslashes in the second line escape the following
spaces.</p>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id9" id="pep-reference" name="pep-reference"><tt class="docutils literal"><span class="pre">:pep-reference:</span></tt></a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Aliases:</th><td class="field-body"><p class="first"><tt class="docutils literal"><span class="pre">:PEP:</span></tt></p>
</td>
</tr>
<tr class="field"><th class="field-name">DTD Element:</th><td class="field-body"><p class="first">reference</p>
</td>
</tr>
<tr class="field"><th class="field-name">Customization:</th><td class="field-body"><table class="first last docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Options:</th><td class="field-body"><a class="reference" href="#class">class</a>.</td>
</tr>
<tr class="field"><th class="field-name">Content:</th><td class="field-body">None.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>The <tt class="docutils literal"><span class="pre">:pep-reference:</span></tt> role is used to create an HTTP reference to a
PEP (Python Enhancement Proposal).  The <tt class="docutils literal"><span class="pre">:PEP:</span></tt> alias is usually
used.  For example:</p>
<pre class="literal-block">See :PEP:`287` for more information about reStructuredText.
</pre>
<p>This is equivalent to:</p>
<pre class="literal-block">See `PEP 287`__ for more information about reStructuredText.

__ http://www.python.org/peps/pep-0287.html
</pre>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id10" id="rfc-reference" name="rfc-reference"><tt class="docutils literal"><span class="pre">:rfc-reference:</span></tt></a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Aliases:</th><td class="field-body"><p class="first"><tt class="docutils literal"><span class="pre">:RFC:</span></tt></p>
</td>
</tr>
<tr class="field"><th class="field-name">DTD Element:</th><td class="field-body"><p class="first">reference</p>
</td>
</tr>
<tr class="field"><th class="field-name">Customization:</th><td class="field-body"><table class="first last docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Options:</th><td class="field-body"><a class="reference" href="#class">class</a>.</td>
</tr>
<tr class="field"><th class="field-name">Content:</th><td class="field-body">None.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>The <tt class="docutils literal"><span class="pre">:rfc-reference:</span></tt> role is used to create an HTTP reference to an
RFC (Internet Request for Comments).  The <tt class="docutils literal"><span class="pre">:RFC:</span></tt> alias is usually
used.  For example:</p>
<pre class="literal-block">See :RFC:`2822` for information about email headers.
</pre>
<p>This is equivalent to:</p>
<pre class="literal-block">See `RFC 2822`__ for information about email headers.

__ http://www.faqs.org/rfcs/rfc2822.html
</pre>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id11" id="strong" name="strong"><tt class="docutils literal"><span class="pre">:strong:</span></tt></a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Aliases:</th><td class="field-body"><p class="first">None</p>
</td>
</tr>
<tr class="field"><th class="field-name">DTD Element:</th><td class="field-body"><p class="first">strong</p>
</td>
</tr>
<tr class="field"><th class="field-name">Customization:</th><td class="field-body"><table class="first last docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Options:</th><td class="field-body"><a class="reference" href="#class">class</a>.</td>
</tr>
<tr class="field"><th class="field-name">Content:</th><td class="field-body">None.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>Implements strong emphasis.  These are equivalent:</p>
<pre class="literal-block">**text**
:strong:`text`
</pre>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id12" id="subscript" name="subscript"><tt class="docutils literal"><span class="pre">:subscript:</span></tt></a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Aliases:</th><td class="field-body"><p class="first"><tt class="docutils literal"><span class="pre">:sub:</span></tt></p>
</td>
</tr>
<tr class="field"><th class="field-name">DTD Element:</th><td class="field-body"><p class="first">subscript</p>
</td>
</tr>
<tr class="field"><th class="field-name">Customization:</th><td class="field-body"><table class="first last docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Options:</th><td class="field-body"><a class="reference" href="#class">class</a>.</td>
</tr>
<tr class="field"><th class="field-name">Content:</th><td class="field-body">None.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>Implements subscripts.</p>
<div class="tip">
<p class="first admonition-title">Tip</p>
<p>Whitespace or punctuation is required around interpreted text, but
often not desired with subscripts &amp; superscripts.
Backslash-escaped whitespace can be used; the whitespace will be
removed from the processed document:</p>
<pre class="literal-block">H\ :sub:`2`\ O
E = mc\ :sup:`2`
</pre>
<p>In such cases, readability of the plain text can be greatly
improved with substitutions:</p>
<pre class="literal-block">The chemical formula for pure water is |H2O|.

.. |H2O| replace:: H\ :sub:`2`\ O
</pre>
<p class="last">See <a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html">the reStructuredText spec</a> for further information on
<a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#character-level-inline-markup">character-level markup</a> and <a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#substitution-references">the substitution mechanism</a>.</p>
</div>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id13" id="superscript" name="superscript"><tt class="docutils literal"><span class="pre">:superscript:</span></tt></a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Aliases:</th><td class="field-body"><p class="first"><tt class="docutils literal"><span class="pre">:sup:</span></tt></p>
</td>
</tr>
<tr class="field"><th class="field-name">DTD Element:</th><td class="field-body"><p class="first">superscript</p>
</td>
</tr>
<tr class="field"><th class="field-name">Customization:</th><td class="field-body"><table class="first last docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Options:</th><td class="field-body"><a class="reference" href="#class">class</a>.</td>
</tr>
<tr class="field"><th class="field-name">Content:</th><td class="field-body">None.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>Implements superscripts.  See the tip in <a class="reference" href="#subscript">:subscript:</a> above.</p>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id14" id="title-reference" name="title-reference"><tt class="docutils literal"><span class="pre">:title-reference:</span></tt></a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Aliases:</th><td class="field-body"><p class="first"><tt class="docutils literal"><span class="pre">:title:</span></tt>, <tt class="docutils literal"><span class="pre">:t:</span></tt>.</p>
</td>
</tr>
<tr class="field"><th class="field-name">DTD Element:</th><td class="field-body"><p class="first">title_reference</p>
</td>
</tr>
<tr class="field"><th class="field-name">Customization:</th><td class="field-body"><table class="first last docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Options:</th><td class="field-body"><a class="reference" href="#class">class</a>.</td>
</tr>
<tr class="field"><th class="field-name">Content:</th><td class="field-body">None.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>The <tt class="docutils literal"><span class="pre">:title-reference:</span></tt> role is used to describe the titles of
books, periodicals, and other materials.  It is the equivalent of the
HTML "cite" element, and it is expected that HTML writers will
typically render "title_reference" elements using "cite".</p>
<p>Since title references are typically rendered with italics, they are
often marked up using <tt class="docutils literal"><span class="pre">*emphasis*</span></tt>, which is misleading and vague.
The "title_reference" element provides accurate and unambiguous
descriptive markup.</p>
<p>Let's assume <tt class="docutils literal"><span class="pre">:title-reference:</span></tt> is the default interpreted text
role (see below) for this example:</p>
<pre class="literal-block">`Design Patterns` [GoF95]_ is an excellent read.
</pre>
<p>The following document fragment (<a class="reference" href="http://docutils.sourceforge.net/docs/ref/doctree.html#pseudo-xml">pseudo-XML</a>) will result from
processing:</p>
<pre class="literal-block">&lt;paragraph&gt;
    &lt;title_reference&gt;
        Design Patterns

    &lt;citation_reference refname="gof95"&gt;
        GoF95
     is an excellent read.
</pre>
<p><tt class="docutils literal"><span class="pre">:title-reference:</span></tt> is the default interpreted text role in the
standard reStructuredText parser.  This means that no explicit role is
required.  Applications of reStructuredText may designate a different
default role, in which case the explicit <tt class="docutils literal"><span class="pre">:title-reference:</span></tt> role
must be used to obtain a <tt class="docutils literal"><span class="pre">title_reference</span></tt> element.</p>
</div>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id15" id="specialized-roles" name="specialized-roles">Specialized Roles</a></h1>
<div class="section">
<h2><a class="toc-backref" href="#id16" id="raw" name="raw"><tt class="docutils literal"><span class="pre">raw</span></tt></a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Aliases:</th><td class="field-body"><p class="first">None</p>
</td>
</tr>
<tr class="field"><th class="field-name">DTD Element:</th><td class="field-body"><p class="first">raw</p>
</td>
</tr>
<tr class="field"><th class="field-name">Customization:</th><td class="field-body"><table class="first last docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field"><th class="field-name">Options:</th><td class="field-body"><a class="reference" href="#class">class</a>, format</td>
</tr>
<tr class="field"><th class="field-name">Content:</th><td class="field-body">None</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<div class="warning">
<p class="first admonition-title">Warning</p>
<p>The "raw" role is a stop-gap measure allowing the author to bypass
reStructuredText's markup.  It is a "power-user" feature that
should not be overused or abused.  The use of "raw" ties documents
to specific output formats and makes them less portable.</p>
<p class="last">If you often need to use "raw"-derived interpreted text roles or
the "raw" directive, that is a sign either of overuse/abuse or that
functionality may be missing from reStructuredText.  Please
describe your situation in a message to the <a class="reference" href="http://docutils.sourceforge.net/docs/user/mailing-lists.html#docutils-user">Docutils-users</a> mailing
list.</p>
</div>
<p>The "raw" role indicates non-reStructuredText data that is to be
passed untouched to the Writer.  It is the inline equivalent of the
<a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/directives.html#raw">"raw" directive</a>; see its documentation for details on the
semantics.</p>
<p>The "raw" role cannot be used directly.  The <a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/directives.html#role">"role" directive</a> must
first be used to build custom roles based on the "raw" role.  One or
more formats (Writer names) must be provided in a "format" option.</p>
<p>For example, the following creates an HTML-specific "raw-html" role:</p>
<pre class="literal-block">.. role:: raw-html(raw)
   :format: html
</pre>
<p>This role can now be used directly to pass data untouched to the HTML
Writer.  For example:</p>
<pre class="literal-block">If there just *has* to be a line break here,
:raw-html:`&lt;br /&gt;`
it can be accomplished with a "raw"-derived role.
But the line block syntax should be considered first.
</pre>
<div class="tip">
<p class="first admonition-title">Tip</p>
<p class="last">Roles based on "raw" should clearly indicate their origin, so
they are not mistaken for reStructuredText markup.  Using a "raw-"
prefix for role names is recommended.</p>
</div>
<p>In addition to "<a class="reference" href="#class">class</a>", the following option is recognized:</p>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">format</span></tt> <span class="classifier-delimiter">:</span> <span class="classifier">text</span></dt>
<dd>One or more space-separated output format names (Writer names).</dd>
</dl>
</div>
</div>
</div>
<div class="footer">
<hr class="footer">
<a class="reference" href="http://docutils.sourceforge.net/docs/ref/rst/roles.txt">View document source</a>.
Generated on: 2006-05-22 14:45 UTC.
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.

</div>
</body></html>